#include <avr/io.h>
#include <avr/interrupt.h>
#include "define.h"
#include "FreeRTOS_encoder.h"

int volatile	L_ecdr_vbuf;
int volatile	R_ecdr_vbuf;
int volatile	L_ecdr_sbuf;
int volatile	R_ecdr_sbuf;

void init_encoder(void)
{
    DDRD  &= 0x03;
	PORTD |= 0xFC;
    DDRE  &= 0x3F;
	PORTE |= 0xC0;
	L_ecdr_vbuf = 0;
	R_ecdr_vbuf = 0;
	L_ecdr_sbuf = 0;
	R_ecdr_sbuf = 0;
}
//Right encoder ISR
ISR(INT7_vect)
{                      
    //init_encoder();
    if((PIND & 0x80) == 0x80){
		//R_ecdr_vbuf++;
		R_ecdr_sbuf++;
	}
	else{
		//R_ecdr_vbuf--;
		R_ecdr_sbuf--;

		
	}
}
//Left encoder ISR
ISR(INT6_vect)
{                      
    //init_encoder();
    if((PIND & 0x40) == 0x40){
		//L_ecdr_vbuf--;
		L_ecdr_sbuf--;
	}
	else{
		//L_ecdr_vbuf++;
		L_ecdr_sbuf++;
		
	}
}
//External interrupt 2 service routine
ISR(INT2_vect)
{                      

}

//External interrupt 3 service routine
ISR(INT3_vect)
{                      

}
